package com.frxuexi.mdm2207.demo

import android.util.Log
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil3.compose.AsyncImage
import com.frxuexi.mdm2207.R

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    /*Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
        Text(
            text = "Hello $name!",
            modifier = modifier,
            fontSize = 16.sp
        )
        Text(text = "bb")
        Text(text = "bb")
    }*/
    var uname by remember {
        mutableStateOf("")
    }
    var pass by remember {
        mutableStateOf("")
    }

    Column(
        modifier = Modifier.fillMaxSize(),
        verticalArrangement = Arrangement.spacedBy(10.dp)/*, horizontalAlignment = Alignment.CenterHorizontally*/
    ) {
        Text(
            text = "Hello fasghdjfkggsdsdfdfdg $name!",
            modifier = modifier.width(300.dp),
            fontSize = 16.sp,
            color = colorResource(id = R.color.purple_200),
            fontWeight = FontWeight.Bold,
            letterSpacing = 5.sp,
            textAlign = TextAlign.Center,
            maxLines = 1,
            overflow = TextOverflow.Ellipsis
        )
        Spacer(modifier = Modifier.height(20.dp))
        Text(text = "bb", modifier = Modifier.clickable {
            Log.i("===","bb点击了")
        })
        Text(text = "bb", modifier = Modifier
//            .size(100.dp)
//            .size(DpSize(100.dp,50.dp))
//            .size(100.dp,50.dp)
            .width(100.dp)
            .height(80.dp)
            .background(Color.Green, RoundedCornerShape(20.dp))
            .border(1.dp, Color.Blue, RoundedCornerShape(20.dp))
            .padding(10.dp)
//            .background(Color.Yellow)
            .offset(x=50.dp,y=-10.dp)
        )

        TextField(value = uname, onValueChange = {
            uname = it
        }, label = { Text(text = "请输入用户名") },
            leadingIcon = {
                Icon(imageVector = Icons.Default.AccountCircle, contentDescription = "")
            }, trailingIcon = {
//                Icon(painter = painterResource(id = R.drawable.ic_action_pass), contentDescription = "")
                Text(text = "验证码", Modifier.padding(horizontal = 10.dp))
            },
            visualTransformation= PasswordVisualTransformation(),
            shape = RoundedCornerShape(topStart=20.dp, topEnd = 20.dp)
        )

        OutlinedTextField(value = pass, onValueChange = {pass=it}
            , label = { Text(text = "请输入用户名") },
            leadingIcon = {
                Icon(imageVector = Icons.Default.AccountCircle, contentDescription = "")
            }, trailingIcon = {
//                Icon(painter = painterResource(id = R.drawable.ic_action_pass), contentDescription = "")
                Text(text = "验证码", Modifier.padding(horizontal = 10.dp))
            },
            visualTransformation= PasswordVisualTransformation()
        )
        Button(onClick = {  }, shape = RoundedCornerShape(40.dp),colors= ButtonDefaults.buttonColors(
            containerColor= Color.Yellow, contentColor = Color.Red
        ), border = BorderStroke(1.dp, Color.DarkGray),) {
            Text(text = "登录")
        }
        FilledTonalButton(onClick = { /*TODO*/ }) {
            Text(text = "登录")
        }
        OutlinedButton(onClick = { /*TODO*/ }) {
            Text(text = "登录")
        }
        ElevatedButton(onClick = { /*TODO*/ }) {
            Text(text = "登录")
        }
        TextButton(onClick = { /*TODO*/ }) {
            Text(text = "登录")
        }
        /*Image(painter = painterResource(id = R.drawable.ic_launcher_background), contentDescription = "", alpha = 0.5f,
            modifier = Modifier.clip(
//                RoundedCornerShape(20.dp)
                CircleShape
            )
        )*/
        AsyncImage(model = "https://img0.baidu.com/it/u=3710358681,2408493409&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1733936400&t=a02568906bdd5de6b5f86639f1534d5e", contentDescription = "")
    }
}